import {
  createRouter,
  createWebHistory,
  createWebHashHistory,
  RouteRecordRaw
} from 'vue-router'
import Layout from '@/layout/component/router-view.vue'

/**
 * title 标题
 * isHide 是否隐藏路由
 * icon 图标
 * isAffix 是否固定头部窗口菜单
 * isKeepActive
 */

// 公共路由
const routerPublics: Array<RouteRecordRaw> = [
  {
    path: '/login',
    name: 'login',
    component: () => import('@/views/login/index.vue')
  },
  {
    path: '/404',
    name: '404',
    component: () => import('@/views/404.vue')
  },
  {
    // 此处vue3更新需要使用catchall方法匹配,不然会出现错误:
    // Catch all routes ("*") must now be defined using a param with a custom regexp
    path: '/:catchAll(.*)',
    redirect: '/404'
  }
]

const route: Array<RouteRecordRaw> = [
  {
    path: '/',
    redirect: '/home',
    name: 'Layout',
    component: () => import('../layout/index.vue'),
    children: [
      {
        path: '/large-screen',
        name: 'largeScreen',
        component: () => import('@/views/large-screen/home/index.vue'),
        meta: {
          title: '大屏',
          isHide: false,
          isAffix: true,
          icon: 'HomeFilled',
          isKeepActive: true // 无法缓存还没找到相关问题
        },
        children: []
      },
      {
        path: '/large-screen/equipment',
        name: 'largeScreenEquipment',
        component: () => import('@/views/large-screen/equipment/index.vue'),
        meta: {
          title: '设备',
          isHide: true,
          isAffix: true,
          icon: 'HomeFilled',
          isKeepActive: true // 无法缓存还没找到相关问题
        }
      },
      {
        path: '/home',
        name: 'Home',
        component: () => import('@/views/home/index.vue'),
        meta: {
          title: '首页',
          isHide: false,
          isAffix: true,
          icon: 'HomeFilled',
          isKeepActive: true // 无法缓存还没找到相关问题
        }
      },
      {
        path: '/swiper',
        name: 'Swiper',
        component: () => import('@/views/Swiper.vue'),
        meta: {
          title: '轮播',
          isHide: false,
          isAffix: false,
          icon: 'HomeFilled'
        }
      },
      {
        path: '/lx',
        name: 'Lx',
        component: () => import('@/views/Lx.vue'),
        meta: {
          title: '练习',
          isHide: false,
          isAffix: false,
          icon: 'HomeFilled'
        }
      },
      {
        path: '/table',
        name: 'TableAntd',
        component: Layout,
        meta: {
          title: 'antd表格表单',
          isHide: false,
          icon: 'Histogram'
        },
        children: [
          {
            path: '/table/row',
            name: 'tableAntdRow',
            component: () => import('@/views/table/index.vue'),
            meta: {
              title: '添加行',
              isHide: false
            }
          },
          {
            path: '/table/page',
            name: 'tableAntdPage',
            component: () => import('@/views/table/page.vue'),
            meta: {
              title: '分页',
              isHide: false
            }
          },
          {
            path: '/table/page2',
            name: 'tableAntdPage2',
            component: () => import('@/views/table/page2.vue'),
            meta: {
              title: '分页2',
              isHide: false
            }
          }
        ]
      },
      {
        path: '/tabs',
        name: 'Tabs',
        component: () => import('@/views/tabs/index.vue'),
        meta: {
          title: '静态资源动态导入',
          isHide: false,
          isAffix: false,
          icon: 'Histogram'
        }
      },
      {
        path: '/array',
        name: 'Array',
        component: () => import('@/views/array/index.vue'),
        meta: {
          title: '数组方法',
          isHide: true,
          icon: 'Histogram'
        }
      },
      {
        path: '/stat',
        name: 'Stat',
        component: () => import('@/views/Stat.vue'),
        meta: {
          title: '数据统计',
          isHide: false,
          icon: 'Histogram'
        }
      },
      {
        path: '/limit',
        name: 'Limit',
        component: () => import('@/views/limit/index.vue'),
        meta: {
          title: '权限管理',
          isHide: false,
          icon: 'Menu'
        }
      },
      {
        path: '/case',
        name: 'Case',
        component: Layout,
        meta: {
          title: '案例',
          isHide: false,
          icon: 'Setting'
        },
        children: [
          {
            path: '/case/mergeColumns',
            name: 'caseMergeColumns',
            component: () => import('@/views/case/mergeColumns/index.vue'),
            meta: {
              title: '合并列',
              isHide: false
            }
          },
          {
            path: '/case/mergeColumns2',
            name: 'caseMergeColumns2',
            component: () => import('@/views/case/mergeColumns2/index.vue'),
            meta: {
              title: '合并列2',
              isHide: false
            }
          }
        ]
      },
      {
        path: '/system',
        name: 'System',
        component: Layout,
        meta: {
          title: '系统设置',
          isHide: false,
          icon: 'Setting'
        },
        children: [
          {
            path: '/system/user',
            name: 'systemUser',
            component: () => import('@/views/system/user/index.vue'),
            meta: {
              title: '用户管理',
              isHide: false
            }
          },
          {
            path: '/system/user/detail/:id',
            name: 'systemDetails',
            component: () =>
              import('@/views/system/user/component/details.vue'),
            meta: {
              title: '用户详情',
              isHide: true,
              isAffix: true
            }
          },
          {
            path: '/system/methods',
            name: 'systemMethods',
            component: () => import('@/views/system/methods/index.vue'),
            meta: {
              title: '实用方法',
              isHide: false
            }
          }
        ]
      }
    ]
  }
]

const routes = route.concat(routerPublics)

const router = createRouter({
  history: createWebHistory(),
  routes
})

export default router
